<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>上架商品</title>
<script type="text/javascript" src="js/jquery.min.js"></script>
<script type="text/javascript">
$(function(){
	$.post("${pageContext.request.contextPath}/itemSelect",
			function(data){
				$.each(data,function(n,item){
					var column = '<option value= '+item.categoryId+'>'+item.categoryName+'</option>';
					$("#selectCategory").append(column);
				}); 
			},
			"json"
	);
});
	$(function() {
		$("#selectCategory").change(function() {
			$("input[type='text']").val("");//清空记录
			var checkIndex = $("#selectCategory").get(0).selectedIndex; //获取Select选择的值
			var categoryId = $("#selectCategory").val();
			$("#categoryId").val(categoryId);
			$(".shop").show();
			if (checkIndex == 0) {
				$(".shop").hide();
				$(".food").hide();
				$(".book").hide();
				$(".clothes").hide();
			} else if (checkIndex == 1) {
				$(".book").show();
				$(".clothes").hide();
				$(".food").hide();
			} else if (checkIndex == 2) {
				$(".clothes").show();
				$(".book").hide();
				$(".food").hide();
			} else if (checkIndex == 3) {
				$(".food").show();
				$(".book").hide();
				$(".clothes").hide();
			}
		});
	});

	//判断该商品是否已存在
	$(function() {
		$("#shopName").blur(function() {
			$(".shop font").remove();
			if(this.value!=null && this.value!="") {
				$.post(
						"${pageContext.request.contextPath}/shopNameVaildate",
						{shopName:this.value},
						function(data){
							if(data != null){
								$("#shopName").after("<font color='red'>该商品已存在，无需上架，请到修改页面直接增加</font>");
							}
						},
						"json"
				);
			}
		});
	});
	
	function doSubmit(){
		var font=$(".shop font").text();
		if(font=="" || font==null){
			$("#addForm").attr("action","${pageContext.request.contextPath}/shopAdd");
			$("#addForm").submit();
		} 
	}
</script>
</head>
<body>
	商品分类选择：
	<select id="selectCategory">
		<option value="0">--请选择--</option>
	</select>
	<form id="addForm" method="post">
		<input id="categoryId" name="category" value="" style="display: none">
		<div class="shop" style="display: none">
			商品名：<input id="shopName" type="text" name="shop.shopName">
		</div>
		<div class="shop" style="display: none">
			商品价格：<input type="text" name="shop.shopPrice">
		</div>
		<div class="shop" style="display: none">
			商品数量： <input type="text" name="shop.shopCount">
		</div>
		<div class="book" style="display: none">
			出版社： <input type="text" name="book.bookPress">
		</div>
		<div class="clothes" style="display: none">
			衣服颜色： <input type="text" name="clothes.clothesColor">
		</div>
		<div class="clothes" style="display: none">
			衣服品牌： <input type="text" name="clothes.clothesBrand">
		</div>
		<div class="food" style="display: none">
			生产日期： <input type="date" name="food.foodProdeceDate">
		</div>
		<div class="food" style="display: none">
			有效期： <input type="text" name="food.foodVaild">
		</div>
		<input type="button" value="上架" onclick="doSubmit()">
	</form>
</body>
</html>